
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>使用本地缓存 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="缓存是高并发程序开发中的一大利器,利用缓存我们能够显著有效的提高程序的响应能力,缓存服务器和数据库的压力,市面上常用的缓存有单机缓存memcached，集群缓存redis等等, 对于大型互联网项目的高并发场景我们使用第三方缓存插件是首选,但是对于一些并发不是很大,但是频繁访问数据库也会影响性能和带来压力的一些场景,我们可以是用本地缓存来 提高程序响应速度和缓解服务器和数据可压力,常用的本地缓存有g">
<meta name="keywords" content="使用本地缓存">
<meta property="og:type" content="article">
<meta property="og:title" content="使用本地缓存">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2017/08/28/使用本地缓存/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="缓存是高并发程序开发中的一大利器,利用缓存我们能够显著有效的提高程序的响应能力,缓存服务器和数据库的压力,市面上常用的缓存有单机缓存memcached，集群缓存redis等等, 对于大型互联网项目的高并发场景我们使用第三方缓存插件是首选,但是对于一些并发不是很大,但是频繁访问数据库也会影响性能和带来压力的一些场景,我们可以是用本地缓存来 提高程序响应速度和缓解服务器和数据可压力,常用的本地缓存有g">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/3.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/4.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/6.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/5.png">
<meta property="og:updated_time" content="2017-08-28T05:01:48.429Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用本地缓存">
<meta name="twitter:description" content="缓存是高并发程序开发中的一大利器,利用缓存我们能够显著有效的提高程序的响应能力,缓存服务器和数据库的压力,市面上常用的缓存有单机缓存memcached，集群缓存redis等等, 对于大型互联网项目的高并发场景我们使用第三方缓存插件是首选,但是对于一些并发不是很大,但是频繁访问数据库也会影响性能和带来压力的一些场景,我们可以是用本地缓存来 提高程序响应速度和缓解服务器和数据可压力,常用的本地缓存有g">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/08/28/使用本地缓存/1.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2017/08/28/使用本地缓存/" title="使用本地缓存" itemprop="url">使用本地缓存</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2017-08-28T04:10:03.000Z" itemprop="datePublished"> Published 2017-08-28</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、新建maven项目-amp-添加依赖"><span class="toc-number">1.</span> <span class="toc-text">一、新建maven项目&添加依赖</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、实现本地缓存"><span class="toc-number">2.</span> <span class="toc-text">二、实现本地缓存</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、测试本地缓存"><span class="toc-number">3.</span> <span class="toc-text">三、测试本地缓存</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<pre><code>缓存是高并发程序开发中的一大利器,利用缓存我们能够显著有效的提高程序的响应能力,缓存服务器和数据库的压力,市面上常用的缓存有单机缓存memcached，集群缓存redis等等,
对于大型互联网项目的高并发场景我们使用第三方缓存插件是首选,但是对于一些并发不是很大,但是频繁访问数据库也会影响性能和带来压力的一些场景,我们可以是用本地缓存来
提高程序响应速度和缓解服务器和数据可压力,常用的本地缓存有guava的本地cache,以及各个公司自己封装的本地缓存插件(本质上本地缓存是使用Map实现的,差别在于实现方式和性能)
,此篇就使用guava实现本地缓存展开叙述:
</code></pre><a id="more"></a>
<h5 id="一、新建maven项目-amp-添加依赖"><a href="#一、新建maven项目-amp-添加依赖" class="headerlink" title="一、新建maven项目&amp;添加依赖"></a>一、新建maven项目&amp;添加依赖</h5><pre><code>新建一个通用的maven工程,并添加一下guava依赖:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.google.guava&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;guava&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;18.0&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
<h5 id="二、实现本地缓存"><a href="#二、实现本地缓存" class="headerlink" title="二、实现本地缓存"></a>二、实现本地缓存</h5><pre><code>我们借助guava的本地缓存并对其封装,实现我们的本地缓存操作工具类,实现方式如下:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div></pre></td><td class="code"><pre><div class="line">package com.typhoon.demo1.cache;</div><div class="line"></div><div class="line">import java.util.List;</div><div class="line">import java.util.concurrent.Callable;</div><div class="line">import java.util.concurrent.TimeUnit;</div><div class="line"></div><div class="line">import org.apache.commons.lang3.builder.ToStringBuilder;</div><div class="line"></div><div class="line">import com.google.common.cache.Cache;</div><div class="line">import com.google.common.cache.CacheBuilder;</div><div class="line"></div><div class="line">/**</div><div class="line"> * guava本地缓存工具类</div><div class="line"> * </div><div class="line"> * @author Typhoon</div><div class="line"> * @date 2017-05-24 15:48</div><div class="line"> * @since V2.0</div><div class="line"> */</div><div class="line">public abstract class LocalCacheUtil &#123;</div><div class="line"></div><div class="line">	// private static final Logger LOGGER =</div><div class="line">	// LoggerFactory.getLogger(LocalCacheUtil.class);</div><div class="line"></div><div class="line">	private static Cache&lt;Object, Object&gt; cache = CacheBuilder.newBuilder().maximumSize(100)</div><div class="line">			.expireAfterWrite(24, TimeUnit.HOURS).recordStats().build();</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 放入本地缓存</div><div class="line">	 * </div><div class="line">	 * @author Typhoon</div><div class="line">	 * @date 2017-05-24 16:34</div><div class="line">	 * @since V2.0</div><div class="line">	 * @param key</div><div class="line">	 * @param value</div><div class="line">	 */</div><div class="line">	public static void put(Object key, Object value) &#123;</div><div class="line">		if (null == key) &#123;</div><div class="line">			throw new IllegalArgumentException(&quot;key can not be null&quot;);</div><div class="line">		&#125;</div><div class="line">		cache.put(key, value);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 根据key获取value</div><div class="line">	 * </div><div class="line">	 * @author Typhoon</div><div class="line">	 * @date 2017-05-24 15:51</div><div class="line">	 * @since V2.0</div><div class="line">	 * @description</div><div class="line">	 *              &lt;ul&gt;</div><div class="line">	 *              &lt;li&gt;如果key存在返回对应value&lt;/li&gt;</div><div class="line">	 *              &lt;li&gt;如果key不存在返回null&lt;/li&gt;</div><div class="line">	 *              &lt;li&gt;注*:cache.get(key,Callable</div><div class="line">	 *              &lt;Object&gt;)不允许key不存在的情况,但是实际情况下是允许的,需要外层捕获异常&lt;/li&gt;</div><div class="line">	 *              &lt;/ul&gt;</div><div class="line">	 * @param key</div><div class="line">	 * @return &lt;code&gt;Object&lt;/code&gt;</div><div class="line">	 */</div><div class="line">	public static Object get(Object key) &#123;</div><div class="line">		if (null == key) &#123;</div><div class="line">			throw new IllegalArgumentException(&quot;key can not be null&quot;);</div><div class="line">		&#125;</div><div class="line">		return cache.getIfPresent(key);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * &lt;ul&gt;</div><div class="line">	 * &lt;li&gt;根据key获取value,如果获取为null,根据传入的callable使用其他方式获取&lt;/li&gt;</div><div class="line">	 * &lt;li&gt;如果穿进来callable为null,调用&lt;method&gt;get(key)&lt;/method&gt;&lt;/li&gt;</div><div class="line">	 * &lt;/ul&gt;</div><div class="line">	 * </div><div class="line">	 * @author Typhoon</div><div class="line">	 * @date 2017-05-24 16:07</div><div class="line">	 * @since V2.0</div><div class="line">	 * @param key</div><div class="line">	 * @param callable</div><div class="line">	 * @return &lt;result&gt;Object&lt;/result&gt;</div><div class="line">	 */</div><div class="line">	public static Object get(Object key, Callable&lt;? extends Object&gt; callable) &#123;</div><div class="line">		if (null == key) &#123;</div><div class="line">			throw new IllegalArgumentException(&quot;key can not be null&quot;);</div><div class="line">		&#125;</div><div class="line">		if (null == callable) &#123;</div><div class="line">			return get(key);</div><div class="line">		&#125;</div><div class="line">		Object value = null;</div><div class="line">		try &#123;</div><div class="line">			value = cache.get(key, callable);</div><div class="line">		&#125; catch (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">		&#125;</div><div class="line">		return value;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 失效某个key</div><div class="line">	 * </div><div class="line">	 * @author Typhoon</div><div class="line">	 * @date 2017-05-24 16:09</div><div class="line">	 * @since V2.0</div><div class="line">	 * @param key</div><div class="line">	 */</div><div class="line">	public static void invalidateKey(Object key) &#123;</div><div class="line">		if (null == key) &#123;</div><div class="line">			throw new IllegalArgumentException(&quot;key can not be null&quot;);</div><div class="line">		&#125;</div><div class="line">		cache.invalidate(key);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 失效某个key集</div><div class="line">	 * </div><div class="line">	 * @author Typhoon</div><div class="line">	 * @date 2017-05-24 16:09</div><div class="line">	 * @since V2.0</div><div class="line">	 * @param keys</div><div class="line">	 */</div><div class="line">	public static void invalidateKeys(List&lt;Object&gt; keys) &#123;</div><div class="line">		if (null == keys || keys.size() == 0) &#123;</div><div class="line">			throw new IllegalArgumentException(&quot;keys can not be empty&quot;);</div><div class="line">		&#125;</div><div class="line">		cache.invalidateAll(keys);</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><em>分析:</em><br><img src="/typhoon/2017/08/28/使用本地缓存/1.png" alt="result" title="result"></p>
<ul>
<li>上述截图中代码片段创建了一个缓存管理器,设置了最大缓存个数是100,有效时间是24小时</li>
</ul>
<img src="/typhoon/2017/08/28/使用本地缓存/2.png" alt="result" title="result">
<ul>
<li>上述这段代码实现将数据放入缓存</li>
</ul>
<img src="/typhoon/2017/08/28/使用本地缓存/3.png" alt="result" title="result">
<ul>
<li>这段代码实现从本地缓存中取目标数据,guava缓存中的get方法是不允许key不存在的,不存在时候会抛异常出来,但是我们的实际业务场景中是允许key不存在的,所以我们使用getIfpresent方法,允许key不存在</li>
</ul>
<img src="/typhoon/2017/08/28/使用本地缓存/4.png" alt="result" title="result">
<ul>
<li>这段代码是对get方法的重载,可以传进来一个callable,也就是我们首先根据key去本地缓存中取查看数据,如果没有查到就根据传进来的callable逻辑去查询并返回结果,常见的就是callable中使用DB查询<br>注意:如果callable没有传就是用上一个方法get</li>
</ul>
<img src="/typhoon/2017/08/28/使用本地缓存/6.png" alt="result" title="result">
<ul>
<li>这段代码有两个方法,都是失效本地缓存中的key,一个是单个失效一个是批量失效</li>
</ul>
<h5 id="三、测试本地缓存"><a href="#三、测试本地缓存" class="headerlink" title="三、测试本地缓存"></a>三、测试本地缓存</h5><pre><code>编写单元测试类并测试本地缓存:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">package com.typhoon.demo1.consumer;</div><div class="line"></div><div class="line">import java.util.concurrent.Callable;</div><div class="line"></div><div class="line">import org.apache.commons.lang3.builder.ToStringBuilder;</div><div class="line"></div><div class="line">import com.typhoon.demo1.cache.LocalCacheUtil;</div><div class="line">import com.typhoon.demo1.dao.UserDao;</div><div class="line">import com.typhoon.demo1.entity.User;</div><div class="line"></div><div class="line">public class LocalCacheConsumer &#123;</div><div class="line"></div><div class="line">	public static void main(String[] args) &#123;</div><div class="line">		</div><div class="line">		final Long id = 1L;</div><div class="line">		</div><div class="line">		String key = &quot;user:id&quot; + id;</div><div class="line">		Object obj = LocalCacheUtil.get(key, new Callable&lt;User&gt;() &#123;</div><div class="line">			public User call() throws Exception &#123;</div><div class="line">				// TODO Auto-generated method stub</div><div class="line">				return new UserDao().getUserById(id);</div><div class="line">			&#125;</div><div class="line">		&#125;);</div><div class="line">		System.out.println(ToStringBuilder.reflectionToString(obj));</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>我们只测试一个方法,上述代码中可以发现,调用得失get(key,callable)方法,
如果本地缓存中根据key查不到数据,会使用callable中的new UserDao().getUserById(id)去数据库查询并返回结果,
运行单元测试方法,可以看到如下结果:
</code></pre><img src="/typhoon/2017/08/28/使用本地缓存/5.png" alt="result" title="result">
<pre><code>可以看到,我们已经拿到想要的结果
</code></pre><h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><pre><code>在有些场景下我们使用本地缓存更加方便和轻量级,但是任何一种事物都有其双面性,我们可以分析出本地缓存的优缺点:
</code></pre><ul>
<li>优点:1)使用方便 2)更轻量级 </li>
<li>缺点:1)不适合大中型项目中的高并发场景,如果强行使用,会拖垮整个应用(本地缓存占用jvm内存)  2)不适合复杂的缓存场景 3)仍然存在缓存穿透问题</li>
</ul>
<p><em>ps</em>:原创不易,多多支持!</p>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/缓存/">缓存</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/使用本地缓存/">使用本地缓存</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2017/08/28/使用本地缓存/" data-title="使用本地缓存 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2017/08/28/spring上下文工具类/" title="spring上下文工具类">
  <strong>上一篇：</strong><br/>
  <span>
  spring上下文工具类</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2017/08/28/缓存穿透解决方案/"  title="缓存穿透解决方案">
 <strong>下一篇：</strong><br/> 
 <span>缓存穿透解决方案
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、新建maven项目-amp-添加依赖"><span class="toc-number">1.</span> <span class="toc-text">一、新建maven项目&添加依赖</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、实现本地缓存"><span class="toc-number">2.</span> <span class="toc-text">二、实现本地缓存</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、测试本地缓存"><span class="toc-number">3.</span> <span class="toc-text">三、测试本地缓存</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
